
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class ReplaceFileContents {

    public void replace() {

        String oldFileName = "C:\\Users\\382499\\Documents\\111.txt";
        String tmpFileName = "C:\\Users\\382499\\Documents\\111BK.txt";

        BufferedReader br = null;
        BufferedWriter bw = null;
        
        try {
            br = new BufferedReader(new FileReader(oldFileName));
            bw = new BufferedWriter(new FileWriter(tmpFileName));
            String line;
            while ((line = br.readLine()) != null) {
                if (line.contains("fever")) {
                    line = line.replace("fever", "cough");
                }
                bw.write(line + "\r\n");
            }
        } catch (Exception e) {
            //return;
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                //
            }
            try {
                if (bw != null) {
                    bw.close();
                }
            } catch (IOException e) {

            }
        }

// Once everything is complete, delete old file..
        File oldFile = new File(oldFileName);
        oldFile.delete();

// And rename tmp file's name to old file name
        File newFile = new File(tmpFileName);
        newFile.renameTo(oldFile);

    }

}
